home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Standard question - pointer initialization
- Date: 15 Mar 1996 18:06:46 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Mar15110646@qcd.lanl.gov>
- References: <4hk9un$906@hammer.msfc.nasa.gov> <4hl6rr$nde@news.xs4all.nl>
- <313E6028.1C19@ix.netcom.com> <4hnpsl$g8c@hacgate2.hac.com>
- <4hq9hsINN998@keats.ugrad.cs.ubc.ca> <4i7cgn$5da@baygull.rtd.com>
- <TANMOY.96Mar13184413@qcd.lanl.gov> <3148D7DB.31C3@hawaii.edu>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: Dave Carien's message of Thu, 14 Mar 1996 18:37:15 -0800
-
- In article <3148D7DB.31C3@hawaii.edu>
- Dave Carien <davec@hawaii.edu> writes:
- <snip>
- DC: I was under the impression that NULL was a pointer type and to convert it
-
- The type of the macro NULL is not specified by the standard: NULL can
- only be used legally in contexts where the expected pointer type is
- already known.
-
- Thus
-
- int i = NULL; is wrong (int expected not pointer)
- int *i = NULL; is okay (int * expected)
- printf("%p\n",NULL); is wrong (compiler does not know what type is
- expected in the varargs part of a function).
-
- DC: to a char type it you would need to do something such as:
- DC:
- DC: (char)NULL
- DC:
-
- (char)NULL is not a legal construct for all possible definitions of
- NULL. Thus NULL could be ((void*)0), in which case (char)NULL would
- try to convert a void* to a char. An implementation is free not to
- define such a conversion.
-
- DC: Of course it would be wiser to use '\0', or just 0 for an int typecast.
-
- Even if it is permitted, the implementation need not choose
- (char)(void*)0 to be the same as (char)0.
-
- And by the way, '\0' is an int in C (it is char in C++: but that is a
- different language). '\0' and 0 are thus _identical_ in type and
- value, the difference in use is stylistic.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-